# opengate Makefile

TARGET  = opengate
VERSION = 0.1.0
SECTION = 1

# includes and libs
SDIR = src
DDIR = doc

MAN  = ${TARGET}.${SECTION}
SMAN = ${DDIR}/${MAN}

SRC = $(shell echo ${SDIR}/*.sh)

# paths
PREFIX = /usr
DESTDIR=/opt/chroot make install
BINDIR = ${DESTDIR}${PREFIX}/bin
MANDIR = ${DESTDIR}${PREFIX}/share/man


all: header ${TARGET}

header:
	@echo ${TARGET} - ${VERSION}
	@echo

${TARGET}:
	@echo Making ${TARGET}
	@echo cp ${SRC} ./
	@cp ${SRC} ./${TARGET}
	@chmod +x ${TARGET}

clean:
	@echo cleaning
	@rm -f ${TARGET} ${TARGET}-${VERSION}.tar.xz

dist: clean
	@echo creating dist tarball
	@mkdir -p ${TARGET}-${VERSION}
	@cp -R COPYING Makefile README.md ${DDIR} ${SDIR} ${TARGET}-${VERSION}
	@tar -cf - ${TARGET}-${VERSION}/ | xz -9 -c - > ${TARGET}-${VERSION}.tar.xz
	@rm -rf ${TARGET}-${VERSION}

install: all
	@echo installing ${TARGERT} at ${BINDIR}
	@mkdir -p ${BINDIR}
	@cp -f ${TARGET} ${BINDIR}
	@chmod 755 ${BINDIR}/${TARGET}
	@echo installing man page at  ${MANDIR}/man${SECTION}
	@mkdir -p ${MANDIR}/man${SECTION}
	@sed "s/VERSION/${VERSION}/g" < ${SMAN} > ${MANDIR}/man${SECTION}/${MAN}
	@chmod 644 ${MANDIR}/man${SECTION}/${MAN}
	@gzip ${MANDIR}/man${SECTION}/${MAN}

uninstall:
	@echo removing ${TARGET} from ${BINDIR}
	@rm -f ${BINDIR}/${TARGET}
	@echo removing man page from ${MANDIR}/man${SECTION}
	@rm -f ${MANDIR}/man${SECTION}/${MAN}.gz

.PHONY: all header clean dist install uninstall

